#include<vector>
#include<iostream>
using namespace std;

const int INF = INT_MAX / 2;

void floyd(vector<vector<int> > &graph){
  int n = graph.size();
  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(graph[i][j] != INF && graph[k][j] != INF){
          graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
        }
      }
    }
  }
}

void printVector(vector<vector<int> > v){
  for(vector<int>v1 : v){
    for(int i: v1){
      if(i == INF){
        cout<<"INF ";
        continue;
      }
      cout<<i<<" ";
    }
    cout<<endl;
  }
}

int main(){
  int n = 7;
  vector<vector<int> > graph(n, vector<int>(n, INF));
  graph[0][1] = 6;
  graph[0][3] = 2;
  graph[1][2] = 5;
  graph[1][5] = 3;
  graph[3][1] = 7;
  graph[3][4] = 5;
  graph[4][5] = 5;
  graph[4][6] = 1;
  graph[5][2] = 3;

  printVector(graph);
  floyd(graph);
  cout << "-----after floyd:" << endl;
  printVector(graph);

  return 0;
}